package s

import org.apache.lucene.index.AtomicReader
import org.apache.lucene.index.DocsAndPositionsEnum
import org.apache.lucene.index.Fields
import org.apache.lucene.index.Term
import org.apache.lucene.index.Terms
import org.apache.lucene.index.TermsEnum
import org.apache.lucene.util.BytesRef
import org.apache.lucene.search.DocIdSetIterator;

class Cooc {

	List getWordPairs (AtomicReader ar, List <Term> termList){

		Fields f =ar.fields();
		Terms terms = f.terms(Constants.FIELD_CONTENTS)
		TermsEnum te0 = terms.iterator(null);
		TermsEnum te1 = terms.iterator(null);


		BytesRef t0 = termList[0].bytes();
		BytesRef t1 = termList[1].bytes();

		if ((te0.seekExact(t0, false)==TermsEnum.SeekStatus.FOUND) &&
		(te1.seekExact(t1, false) ==TermsEnum.SeekStatus.FOUND))
		{
			
			DocsAndPositionsEnum de0 =te0.docsAndPositions(null, null)			
			DocsAndPositionsEnum de1 =te1.docsAndPositions(null, null)

			int docid
			while ((docid=de0.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS){
				println "docid " + docid + " fre1 " +  de0.freq()
				
				
				for (int i=0; i<de.freq(); i++){
					println " de.nextpos " + de.nextPosition()
					println " "
				}
			}
		}
	}
}

